//
//  KLColor.h
//  kunlun
//
//  Created by zhusanbao on 2020/9/26.
//  Copyright © 2020 zhusanbao. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "JYBaseStatics.h"

extern NSString *_KL_SAMPLE_COLOR(NSString *hex);

/** 正常，暗黑模式颜色生成 */
static inline UIColor* KLDYColor(NSString *normal, NSString *dark){
    if (@available(iOS 13.0, *)) {
#if DEBUG
//        NSArray *stacks = NSThread.callStackSymbols;
//        void (^debug_block)(void) = ^{
//            NSLog(@"⚠️⚠️⚠️⚠️颜色值[%@]@@\n%@⚠️⚠️⚠️⚠️\n",normal,stacks);
//        };
        if (normal.length == 0) return nil;
        return [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
            UIColor *color = (traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark && (dark.length)) ? jy_HexColor(dark) :jy_HexColor(normal);
            __PRAGMA_PUSH_NO_EXTRA_ARG_WARNINGS
            if (__builtin_expect(!(color != nil), 0)) {
//                debug_block();
                [[NSAssertionHandler currentHandler] handleFailureInFunction:@"DYColor" file:@(__FILE_NAME__) lineNumber:__LINE__ description:@"Color不可为空 %@:%@",normal,NSThread.callStackSymbols];
            }
            __PRAGMA_POP_NO_EXTRA_ARG_WARNINGS
            return color;
        }];
#else
        return [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
            return (traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark && (dark.length)) ? jy_HexColor(dark) :jy_HexColor(normal);
        }];
#endif
    }else{
        return jy_HexColor(normal);
    }
}
/** 带alpha通道的颜色生成 */
static inline UIColor* KLDYColorWithAlpha(NSString *normal, NSString *dark, CGFloat alpha){
    if (@available(iOS 13.0, *)) {
        if (normal.length == 0)return nil;
        return [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
            return (traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark && (dark.length)) ? [jy_HexColor(dark) colorWithAlphaComponent:alpha] : [jy_HexColor(normal) colorWithAlphaComponent:alpha];
        }];
    }else{
        return [jy_HexColor(normal) colorWithAlphaComponent:alpha];
    }
}
/** 分别带alpha通道的颜色生成 */
static inline UIColor* KLDYColorWithSepAlpha(NSString *normal, NSString *dark, CGFloat a1, CGFloat a2){
    if (@available(iOS 13.0, *)) {
        return [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
            return (traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark && (dark.length)) ? [jy_HexColor(dark) colorWithAlphaComponent:a1] : [jy_HexColor(normal) colorWithAlphaComponent:a2];
        }];
    }else{
        return [jy_HexColor(normal) colorWithAlphaComponent:a1];
    }
}
/** 带alpha通道的颜色: ableDark是否使用暗黑模式*/
static inline UIColor* KLDYAlphaColorWithSwitch(NSString *normal, NSString *dark, CGFloat alpha , BOOL ableDark){
        if (dark.length && ableDark) {
            return KLDYColorWithAlpha(normal,dark,alpha);
        }
    return [jy_HexColor(normal) colorWithAlphaComponent:alpha];
}
static inline UIColor* KLDYColorWithSwitch(NSString *normal, NSString *dark , BOOL ableDark){
    return KLDYAlphaColorWithSwitch(normal, dark, 1.0, ableDark);
}
/** 白色绑定暗黑色值 */
static inline UIColor *KLWhiteColorBindColor(NSString *dark){
    return KLDYColor(@"#FFFFFF", dark);
}
/** 黑色绑定暗黑色值 */
static inline UIColor *KLBlackColorBindColor(NSString *light){
    return KLDYColor(@"#000000", light);
}

/** 固定匹配暗黑模式颜色值*/
static inline UIColor *KLColor(NSString *hex){
    return KLDYColor(hex, _KL_SAMPLE_COLOR(hex.uppercaseString));
}
/** 相同alpha颜色通道值 */
static inline UIColor *KLColorWithAlpha(NSString *hex, CGFloat alpha){
    return KLDYColorWithAlpha(hex, _KL_SAMPLE_COLOR(hex.uppercaseString), alpha);
}
/** 两个alpha颜色通道值 */
static inline UIColor *KLColorWithSepAlpha(NSString *hex, CGFloat a1, CGFloat a2){
    return KLDYColorWithSepAlpha(hex, _KL_SAMPLE_COLOR(hex.uppercaseString), a1, a2);
}
/** 标准白色色值 */
static inline UIColor *KLWhiteColor(){
    return KLDYColor(@"#FFFFFF", _KL_SAMPLE_COLOR(@"#FFFFFF"));
}
/** 标准黑色色值 */
static inline UIColor *KLBlackColor(){
//    return KLDYColor(@"#000000", _KL_SAMPLE_COLOR(@"#000000"));
    return KLDYColor(@"#000000", @"#FFFFFF");
}

static inline UIColor *KLWhiteColor2(){
    return KLDYColor(@"#FFFFFF", @"#313133");
}

NS_ASSUME_NONNULL_BEGIN

@interface KLColors : NSObject


@end

NS_ASSUME_NONNULL_END
